<!--  -->
<template>
  <div class="box">
    <div class="time_select">
      <h1>时间选择：</h1>
      <ul>
        <li
          v-for="(item, index) in timeSelectList"
          :key="index"
          :class="carIndex === index ? 'active' : ''"
          @click="changeTab(index)"
        >
          {{ item.name }}
        </li>
      </ul>
      <div class="time_select_block">
        <el-date-picker v-model="value1" type="date"></el-date-picker>
      </div>
    </div>
    <!-- 砍价状态 -->
    <div class="say_state">
      <h1>砍价状态</h1>
      <el-select
        v-model="commodityState"
        @change="changeDate(pageIndex, pageSize)"
        clearable
        placeholder="请选择"
      >
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
    </div>
    <!-- 分页 -->
    <el-table
      :data="tableData"
      border
      style="width: 100% text-align:center"
      max-height="400"
    >
      <el-table-column prop="id" label="ID" align="center"> </el-table-column>
      <el-table-column prop="url" label="砍价图片" align="center">
        <template slot-scope="scope">
          <img :src="scope.row.url" />
        </template>
      </el-table-column>
      <el-table-column prop="name" label="砍价商品名称" align="center">
      </el-table-column>
      <el-table-column prop="recommend" label="商品介绍" align="center">
      </el-table-column>
      <el-table-column prop="price" label="砍价价格" align="center">
      </el-table-column>
      <el-table-column prop="introduce" label="总共砍次数" align="center">
      </el-table-column>
      <el-table-column prop="residue" label="剩余砍价次数" align="center">
      </el-table-column>
      <el-table-column prop="begin" label="开始时间" align="center">
      </el-table-column>
      <el-table-column prop="finish" label="结束时间" align="center">
      </el-table-column>
      <el-table-column prop="state" label="砍价状态" align="center">
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="compile(scope.row)"
            >查看详情</el-button
          >
          <tk
            v-if="showPile"
            :newList="newList"
            :name="'砍价'"
            @isShow="isShow"
          ></tk>
        </template>
      </el-table-column>
    </el-table>
    <footer>
      <el-pagination
        @current-change="handleCurrentChange"
        background
        layout="prev, pager, next"
        :total="1000"
      />
    </footer>
  </div>
</template>

<script>
import { fetchList } from "../../../../api/productData";
import tk from "../components/tk";
export default {
  //import引入的组件需要注入到对象中才能使用

  components: {},
  data() {
    //这里存放数据
    return {
      timeSelectList: [
        {
          name: "全部",
        },
        {
          name: "今天",
        },
        {
          name: "昨天",
        },
        {
          name: "最近7天",
        },
        {
          name: "最近30天",
        },
        {
          name: "本月",
        },
        {
          name: "本年",
        },
      ],
      options: [
        {
          value: "",
          label: "全部",
        },
        {
          value: "进行中",
          label: "进行中",
        },
        {
          value: "已结束",
          label: "已结束",
        },
        {
          value: "准备中",
          label: "准备中",
        },
      ],
      showPile: false,
      commodityState: null,
      currentPage4: 1,
      tableData: [],
      value1: "",
      carIndex: 0,
      pageIndex: 1,
      pageSize: 5,
      total: 0,
      scops: {},
      value: "",
      flag: false,
      newList: [],
      //分页
      listQuery: {
        page: 1,
        limit: 4,
        sort: "+id",
        total: 0,
      },
    };
  },
  //监听属性 类似于data概念
  computed: {},
  components: { tk },
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    changeDate(ind, page) {
      // console.log(ind, page);
      // console.log(this.commodityState);
      // console.log(this.tableData[0]);
      //获取点击后的状态并赋值
      const data = this.newList.filter(
        (item) => item.state === this.commodityState
      );
      this.tableData = data;
    },
    handleSizeChange() {},
    handleCurrentChange() {},
    //点击查看
    compile(row) {
      this.showPile = !this.showPile;
      this.newList = row;
      console.log(this.newList);
    },
    //传入的事件
    isShow(e) {
      this.showPile = e;
    },
    getList() {
      fetchList(this.listQuery).then((res) => {
        console.log(res);
        this.tableData = res.data.items;
        this.newList = res.data.items;
      });
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList();
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getList();
  },
};
</script>
<style lang="scss" scoped>
* {
  list-style: none;
  box-sizing: border-box;
}
.box {
  width: 100%;
  height: 100%;
  background: #fff;
  padding: 20px 20px 10px 20px;
  display: flex;
  flex-direction: column;
  .active {
    color: #eff5ff !important;
    background: #1890ff;
  }
  .time_select {
    width: 100%;
    height: 65px;
    display: flex;
    align-items: center;
    h1 {
      font-size: 16px;
      font-weight: bolder;
      color: #626168;
    }
    ul {
      margin-left: 20px;
      display: flex;
      height: 39px;
      li {
        height: 39px;
        line-height: 39px;
        padding: 0 20px;
        border: 1px solid #ebecf0;
        color: #676669;
      }
    }
  }
  .say_state {
    width: 100%;
    height: 60px;
    display: flex;
    align-items: center;
    h1 {
      font-size: 16px;
      font-weight: bolder;
      color: #626168;
      margin-right: 10px;
    }
    .el-select {
      height: 40px;
    }
    .search_h1 {
      margin-left: 30px;
    }
  }
  footer {
    width: 100%;
    height: 50px;
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
  }
}
</style>
